﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GrouponDesktop.AbmRol
{
    public partial class AltaRol : Form
    {
        DataGridViewCheckBoxColumn dgv_add = new DataGridViewCheckBoxColumn();


        public AltaRol()
        {
            InitializeComponent();
            dgv_func.Columns.Add(dgv_add);
            dgv_add.ReadOnly = false;
            dgv_add.Name = "agregar";
            dgv_add.ValueType = typeof(bool);
        }


        private void b_alta_Click(object sender, EventArgs e)
        {


            if (cb_tipo.Text == "Cliente")
            {
                BDConnection.execute("EXEC CodingSpree.insertRol '" + tb_rol.Text + "', " + "1");
            }
            if (cb_tipo.Text == "Proveedor")
            {
                BDConnection.execute("EXEC CodingSpree.insertRol '" + tb_rol.Text + "', " + "2");
            }


            foreach (DataGridViewRow dgvR in dgv_func.Rows)
            {

                if ((bool)((DataGridViewCheckBoxCell)dgvR.Cells["agregar"]).FormattedValue)
                {
                    BDConnection.execute("EXEC CodingSpree.insertFunxRol '" + dgvR.Cells["Funcionalidad"].Value.ToString() + "', '" + tb_rol.Text + "'");

                }

            }

            MessageBox.Show("USUARIO DADO DE ALTA");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
                        
            if (cb_tipo.Text == "Cliente")
            {
                BDConnection.FillGrid("EXEC CodingSpree.listarFuncRol 1", dgv_func);
            }

            if (cb_tipo.Text == "Proveedor")
            {
                BDConnection.FillGrid("EXEC CodingSpree.listarFuncRol 2", dgv_func);
            }

            dgv_func.Columns[1].ReadOnly = true;           
        
        }


    }
}
